﻿/******************************************************************
** Copyright (c) 2016 正道远研发中心
** 创建人:  youping
** 创建日期:2019-11-02
** 修改人:
** 修改日期:
** 描 述:  长短路径转换
** 版 本:1.0
**-----------------------------------------------------------------
*******************************************************************/

using System;
using System.Collections.Generic;
using System.Data;

namespace Smart.ShortUrl.BU
{
    using Smart.ShortUrl.BU.Data;
    using Smart.ShortUrl.BU.Model;
    using Smart.Core;

    [Serializable()]
    public class SYSShortUrlTransManager : SYSShortUrlTransData
    {
        public static DataSet Search(DbCon myDbCon, SYSShortUrlTransQuery QueryData)
        {
            string strQuery = @"SELECT "
            + SYSShortUrlTrans.ID_FULL + ","
            + SYSShortUrlTrans.MD5Code_FULL + ","
            + SYSShortUrlTrans.TargetUrl_FULL + ","
            + SYSShortUrlTrans.Remark_FULL + ","
            + SYSShortUrlTrans.Enabled_FULL + ","
            + SYSShortUrlTrans.CreateStaff_FULL + ","
            + SYSShortUrlTrans.CreateDate_FULL + ","
            + SYSShortUrlTrans.ModifyStaff_FULL + ","
            + SYSShortUrlTrans.ModifyDate_FULL + ","
            + " ROW_NUMBER() OVER (ORDER BY " + QueryData.Sort + ") AS ROWNUM"
            + " FROM " + SYSShortUrlTrans.TABLENAME + " WHERE 1 = 1 ";

            bool dbCloce = myDbCon == null;
            Dictionary<String, object> myParam = new Dictionary<String, object>();

            if (QueryData.MD5Code != null && QueryData.MD5Code.Length > 0)
            {
                strQuery += " AND " + SYSShortUrlTrans.MD5Code_FULL + " = @MD5Code ";
                myParam.Add("@MD5Code", QueryData.MD5Code);
            }

            DataSet myDs = new DataSet();
            try
            {
                myDbCon = DbCon.InitCon(myDbCon);
                if (QueryData.IsPaging)
                {
                    myDbCon.FillPage(strQuery, myDs, QueryData.PageIndex, QueryData.PageSize, myParam, SYSShortUrlTrans.TABLENAME);
                }
                else
                {
                    myDbCon.Fill(strQuery, myDs, myParam, SYSShortUrlTrans.TABLENAME);
                }
            }
            catch (Exception myEx)
            {
                myEx.Out(string.Format("\r\n SQL:", strQuery));
                throw new Exception(myEx.Message + "\r\n SQL:" + strQuery);
            }
            finally
            {
                myDbCon.Close(dbCloce);
            }
            return myDs;
        }
    }

    [Serializable()]
    public class SYSShortUrlTransQuery
    {
        public string MD5Code = string.Empty;

        public string Sort = " ID ";

        public bool IsPaging = true;
        public int PageIndex = 1;
        public int PageSize = 30;
        public SYSShortUrlTransQuery()
        {
        }
    }
}
